package interview.firstnonrepeatedchar;

import java.util.HashMap;

public class FirstNonerepeatedChar {
	public Character run(String str) {
		HashMap<Character, Object> map = new HashMap<Character, Object>();
		Object once = new Object();
		Object more = new Object();
		
		char[] charArray = str.toCharArray();
		for(char c : charArray) {
			Object obj = map.get(c);
			if (obj == null) {
				map.put(c, once);
			} else {
				map.put(c, more);
			}
		}
		
		for(char c : charArray) {
			Object obj = map.get(c);
			if (obj == once) {
				return c;
			}
		}
		
		return null;
	}
}
